home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Sample Code / Snippets / Toolbox / Vertest / Vertest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-16  |  10.4 KB  |  410 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________*/
  2. /*                            C Shell                        */
  3. /*                          by                          */
  4. /*                  RICHARD P. COLLYER                  */
  5. /*                       09/02/87                       */
  6. /*______________________________________________________*/
  7.  
  8. #include    <CType.h>
  9. #include    <Quickdraw.h>
  10. #include    <Windows.h>
  11. #include    <OSUtils.h>
  12. #include    <Controls.h>
  13. #include    <desk.h>
  14. #include    <dialogs.h>
  15. #include    <Events.h>
  16. #include    <Files.h>
  17. #include    <Memory.h>
  18. #include    <Menus.h>
  19. #include    <Notification.h>
  20. #include    <OSEvents.h>
  21. #include    <Packages.h>
  22. #include    <Palette.h>
  23. #include    <Resources.h>
  24. #include    <SANE.h>
  25. #include    <SegLoad.h>
  26. #include    <Sound.h>
  27. #include    <String.h>
  28. #include    <ToolUtils.h>
  29. #include    <StdIO.h>
  30. #include    <math.h>
  31.  
  32. extern _DataInit();
  33.  
  34. #define    TRUE            0xFF
  35. #define    FALSE            0
  36. #define    VERSION            1
  37. #define    SR_BIT            0
  38.  
  39. #define    appleID            128            
  40. #define    appleMenu        0
  41. #define    aboutMeCommand    1
  42.  
  43. #define    fileID            129
  44. #define    startCommand    1
  45. #define    quitCommand     2
  46.  
  47. #define    editID            130
  48.  
  49. #define    aboutMeDLOG        128
  50. #define    okButton        1
  51. #define    authorItem        2
  52. #define    languageItem    3
  53.  
  54. #define    nocolorID        130
  55. #define    no68020            133
  56. #define    no68881            132
  57. #define    no256            134
  58. #define    nosys6            135
  59.  
  60. long                Tick;
  61. int                    yieldTime, err, numcolor, offLeft, offTop, offRight, offBottom;
  62. Rect                screenRect, BaseRect, TotalRect, minRect;
  63. WindowPtr            whichWindow, myWindow;
  64. CTabHandle            mycolors;
  65. PaletteHandle        srcPalette;
  66. MenuHandle            mymenu1, mymenu2, mymenu0;
  67. EventRecord         myEvent;
  68. Boolean                DoneFlag;
  69. GDHandle            theGDevice;
  70. SysEnvRec            theWorld;
  71. OSErr                OSys;
  72.     
  73. /*______________________________________________________*/
  74. /*                What ever You want                    */
  75. /*______________________________________________________*/
  76. void start()
  77. {
  78.  
  79.     VersRecHndl version;
  80.     StringPtr messagePtr;
  81.     Str255 longMessage, countsstrPtr;
  82.     //char *countsstrPtr, countstr;
  83.     
  84.     //countsstrPtr = &countstr;
  85.  
  86.     version = (VersRecHndl) GetResource ('vers', 1);
  87.     
  88.     messagePtr = (StringPtr) (((unsigned long) &(**version).shortVersion[1]) + 
  89.             ((**version).shortVersion[0]));
  90.  
  91.     BlockMove((Ptr) messagePtr, &longMessage, ((unsigned char) *messagePtr) + 1);
  92.  
  93. //short version
  94.     MoveTo(10,10);
  95.     DrawString((**version).shortVersion);
  96. //long version
  97.     MoveTo(10,30);
  98.     DrawString(longMessage);
  99. //country code
  100.     MoveTo(10,50);
  101.     NumToString((**version).countryCode,countsstrPtr);
  102.     DrawString(countsstrPtr);
  103. //major rev
  104.     MoveTo(10,70);
  105.     NumToString((**version).numericVersion.majorRev,countsstrPtr);
  106.     DrawString(countsstrPtr);
  107. // minor rev
  108.     MoveTo(10,90);
  109.     NumToString((**version).numericVersion.minorRev,countsstrPtr);
  110.     DrawString(countsstrPtr);
  111. //bug fix rev
  112.     MoveTo(10,110);
  113.     NumToString((**version).numericVersion.bugFixRev,countsstrPtr);
  114.     DrawString(countsstrPtr);
  115. //stage
  116.     MoveTo(10,130);
  117.     NumToString((**version).numericVersion.stage,countsstrPtr);
  118.     DrawString(countsstrPtr);
  119. // non rel rev
  120.     MoveTo(10,150);
  121.     NumToString((**version).numericVersion.nonRelRev,countsstrPtr);
  122.     DrawString(countsstrPtr);
  123.     
  124.     return;
  125. }
  126.  
  127. /*______________________________________________________*/
  128. /*                 About Prog Dialog                    */
  129. /*______________________________________________________*/
  130. void showAboutMeDialog()
  131. {
  132.     GrafPtr     savePort;
  133.     DialogPtr    theDialog;
  134.     short        itemHit;
  135.  
  136.     GetPort(&savePort);
  137.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  138.     SetPort(theDialog);
  139.  
  140.     do {
  141.         ModalDialog(nil, &itemHit);
  142.     } while (itemHit != okButton);
  143.  
  144.     CloseDialog(theDialog);
  145.  
  146.     SetPort(savePort);
  147.     return;
  148. }
  149.  
  150. /*______________________________________________________*/
  151. /*                 Do Menu Function                     */
  152. /*______________________________________________________*/
  153. void doCommand(mResult)
  154.     long    mResult;
  155. {
  156.     int                     theMenu, theItem;
  157.     char                    daName[256];
  158.     GrafPtr                 savePort;
  159.  
  160.     theItem = LoWord(mResult);
  161.     theMenu = HiWord(mResult);
  162.     
  163.     switch (theMenu) {
  164. /*______________________________________________________*/
  165. /*                    Do Apple Menu                     */
  166. /*______________________________________________________*/
  167.         case appleID:
  168.             if (theItem == aboutMeCommand)
  169.                 showAboutMeDialog();
  170.             else {
  171.                 GetItem(mymenu0, theItem, daName);
  172.                 GetPort(&savePort);
  173.                 (void) OpenDeskAcc(daName);
  174.                 SetPort(savePort);
  175.             }
  176.             break;
  177. /*______________________________________________________*/
  178. /*                     Do File Menu                     */
  179. /*______________________________________________________*/
  180.         case fileID:
  181.             switch (theItem) {
  182.                 case startCommand:
  183.                     start();
  184.                     break;
  185.                 case quitCommand:
  186.                     DoneFlag = TRUE;
  187.                     break;
  188.                 default:
  189.                     break;
  190.                 }
  191.             break;
  192. /*______________________________________________________*/
  193. /*                     Do Edit Menu                     */
  194. /*______________________________________________________*/
  195.         case editID:
  196.             switch (theItem) {
  197.                 default:
  198.                     break;
  199.                 }
  200.             break;
  201.         default:
  202.             break;
  203.         }
  204.     HiliteMenu(0);
  205.     return;
  206. }
  207.  
  208. /*______________________________________________________*/
  209. /*               Initialization traps                   */
  210. /*______________________________________________________*/
  211. void init()
  212. {
  213.     RgnHandle        tempRgn;
  214.     
  215.     UnloadSeg(_DataInit);
  216.     InitGraf(&qd.thePort);
  217.     FlushEvents(everyEvent, 0);
  218.     InitWindows();
  219.     InitDialogs(nil);
  220.     InitCursor();
  221. /*______________________________________________________*/
  222. /*            If not right Machine then stop            */
  223. /*______________________________________________________*/
  224.     OSys = SysEnvirons(VERSION,&theWorld);
  225.     /*if(!theWorld.hasColorQD) {
  226.         crashDia = GetNewDialog (nocolorID, nil, (WindowPtr) -1);
  227.         DrawDialog (crashDia);
  228.         Delay (300, tick);
  229.         ExitToShell();
  230.         }
  231.     if(theWorld.processor != env68020) {
  232.         crashDia = GetNewDialog (no68020, nil, (WindowPtr) -1);
  233.         DrawDialog (crashDia);
  234.         Delay (300, tick);
  235.         ExitToShell();
  236.         }
  237.     if(!theWorld.hasFPU) {
  238.         crashDia = GetNewDialog (no68881, nil, (WindowPtr) -1);
  239.         DrawDialog (crashDia);
  240.         Delay (300, tick);
  241.         ExitToShell();
  242.         }
  243.     if(theWorld.systemVersion < 0x0600) {
  244.         crashDia = GetNewDialog (nosys6, nil, (WindowPtr) -1);
  245.         DrawDialog (crashDia);
  246.         Delay (300, tick);
  247.         ExitToShell();
  248.         }*/
  249.             
  250. /*______________________________________________________*/
  251. /*                     Set Rects                        */
  252. /*______________________________________________________*/
  253.     screenRect = qd.screenBits.bounds;
  254.     offLeft = 0;
  255.     offTop = 0;
  256.     offRight = screenRect.right;
  257.     offBottom = screenRect.bottom;
  258.     SetRect(&BaseRect, 40, 60, 472, 282);
  259.     tempRgn = GetGrayRgn();
  260.     HLock ((Handle) tempRgn);
  261.     TotalRect = (**tempRgn).rgnBBox;
  262.     SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40, 
  263.                 (**tempRgn).rgnBBox.bottom - 40);
  264.     HUnlock ((Handle) tempRgn);
  265.  
  266. /*______________________________________________________*/
  267. /*        Open Window & set Palette & Picture           */
  268. /*______________________________________________________*/
  269.     theGDevice = GetMainDevice();
  270.     HLock ((Handle) theGDevice);
  271.     mycolors = (**(**theGDevice).gdPMap).pmTable;
  272.     numcolor = (**(**theGDevice).gdPMap).pixelSize;
  273.     HUnlock((Handle) theGDevice);
  274.     switch (numcolor) {
  275.         case 1:
  276.             numcolor = 2;
  277.             break;
  278.         case 2:
  279.             numcolor = 4;
  280.             break;
  281.         case 4:
  282.             numcolor = 16;
  283.             break;
  284.         case 8:
  285.             numcolor = 256;
  286.             break;
  287.         }
  288.     
  289.     myWindow = NewCWindow(nil, &BaseRect, "", TRUE, zoomDocProc, 
  290.                             (WindowPtr) -1, TRUE, 150);
  291.     SetPort((WindowPtr) myWindow);
  292.     DrawGrowIcon (myWindow);
  293.  
  294.     srcPalette = NewPalette (numcolor, mycolors, pmCourteous, 0);
  295.     SetPalette ((WindowPtr) myWindow, srcPalette, TRUE);
  296.     
  297. /*______________________________________________________*/
  298. /*                    Set menus                         */
  299. /*______________________________________________________*/
  300.     mymenu0 = GetMenu(appleID);
  301.     AddResMenu(mymenu0, 'DRVR');
  302.     InsertMenu(mymenu0,0);
  303.     mymenu1 = newmenu(129,"File");
  304.     appendmenu(mymenu1,"Start;Quit");
  305.     InsertMenu(mymenu1,0);
  306.     mymenu2 = newmenu(130,"Edit");
  307.     InsertMenu(mymenu2,0);
  308.     DrawMenuBar();
  309.  
  310. /*______________________________________________________*/
  311. /*                  Init variables                      */
  312. /*______________________________________________________*/
  313.     DoneFlag = FALSE;
  314.     yieldTime = 0;
  315.     return;
  316. }
  317.  
  318. main()
  319. {
  320.     Boolean        track;
  321.     long        growResult;
  322. /*______________________________________________________*/
  323. /*                   Main Event loop                    */
  324. /*______________________________________________________*/
  325.     init();
  326.     for ( ;; ) {
  327.         if (DoneFlag) {
  328.             ExitToShell();
  329.             }
  330.         if (WaitNextEvent(everyEvent, &myEvent, yieldTime, nil)) {
  331.             switch (myEvent.what) {
  332.                 case mouseDown:
  333.                     switch (FindWindow(myEvent.where, &whichWindow)) {
  334.                         case inSysWindow:
  335.                             SystemClick(&myEvent, whichWindow);
  336.                             break;
  337.                         case inMenuBar:
  338.                             doCommand(MenuSelect(myEvent.where));
  339.                             break;
  340.                         case inContent:
  341.                             break;
  342.                         case inDrag:
  343.                             DragWindow (whichWindow, myEvent.where, &TotalRect);
  344.                             EraseRect (&whichWindow->portRect);
  345.                             DrawGrowIcon (whichWindow);
  346.                             break;
  347.                         case inGrow:
  348.                             growResult = GrowWindow (whichWindow, myEvent.where,
  349.                                                     &minRect);
  350.                             SizeWindow(whichWindow, LoWord(growResult), 
  351.                                     HiWord(growResult), TRUE);
  352.                             EraseRect (&whichWindow->portRect);
  353.                             DrawGrowIcon (whichWindow);
  354.                             break;
  355.                         case inGoAway:
  356.                             track = TrackGoAway (whichWindow, myEvent.where);
  357.                             if (track)
  358.                                 CloseWindow (whichWindow);
  359.                             break;
  360.                         case inZoomIn:
  361.                             track = TrackBox (whichWindow, myEvent.where, inZoomIn);
  362.                             if (track) {
  363.                                 ZoomWindow (whichWindow, inZoomIn, TRUE);
  364.                                 EraseRect (&whichWindow->portRect);
  365.                                 DrawGrowIcon (whichWindow);
  366.                                 }
  367.                             break;
  368.                         case inZoomOut:
  369.                             track = TrackBox (whichWindow, myEvent.where, inZoomOut);
  370.                             if (track) {
  371.                                 ZoomWindow (whichWindow, inZoomOut, TRUE);
  372.                                 EraseRect (&whichWindow->portRect);
  373.                                 DrawGrowIcon (whichWindow);
  374.                                 }
  375.                             break;
  376.                         default:
  377.                             break;
  378.                         }
  379.                     break;
  380.                 case keyDown:
  381.                     break;
  382.                 case autoKey:
  383.                     break;
  384.                 case updateEvt:
  385.                     if ((WindowPtr) myEvent.message == myWindow) {
  386.                         BeginUpdate((WindowPtr) myWindow);
  387.                         EndUpdate((WindowPtr) myWindow);
  388.                         }
  389.                     break;
  390.                 case diskEvt:
  391.                     break;
  392.                 case activateEvt:
  393.                     break;
  394.                 case app4Evt:
  395.                     if ((myEvent.message << 31) == 0) { /* Suspend */
  396.                         yieldTime = 30;
  397.                         HideWindow((WindowPtr) myWindow);
  398.                         }
  399.                     else { /* Resume */
  400.                         yieldTime = 0;
  401.                         ShowWindow((WindowPtr) myWindow);
  402.                         SetPort((WindowPtr) myWindow);
  403.                         }
  404.                     break;
  405.                 default:
  406.                     break;
  407.                 }
  408.             }
  409.         }
  410. }